import config from "@/config"
import http from "@/utils/request"

// 采购
export default {
  // 请购管理
  getPurchaseRequestList: {
    url: `${config.API_URL}/purchaseRequisition/list`,
    name: "获取请购列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addPurchaseRequest: {
    url: `${config.API_URL}/purchaseRequisition/add`,
    name: "添加请购",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updatePurchaseRequest: {
    url: `${config.API_URL}/purchaseRequisition/update`,
    name: "修改请购",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deletePurchaseRequest: {
    url: `${config.API_URL}/purchaseRequisition/delete`,
    name: "删除请购",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getGoodsList: {
    url: `${config.API_URL}/purchaseRequisition/productList`,
    name: "获取请购物品列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getPurchaseRequestById: {
    url: `${config.API_URL}/purchaseRequisition/viewItem`,
    name: "根据id查看多个请购详情",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  createPurchaseOrder: {
    url: `${config.API_URL}/purchaseRequisition/generate`,
    name: "生成采购单",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  cancelOrder: {
    url: `${config.API_URL}/purchaseRequisition/cancel`,
    name: "取消采购单",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 采购管理
  getPurchaseList: {
    url: `${config.API_URL}/procurement/list`,
    name: "获取采购单列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addPurchase: {
    url: `${config.API_URL}/procurement/add`,
    name: "添加采购单",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updatePurchase: {
    url: `${config.API_URL}/procurement/update`,
    name: "修改采购单",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deletePurchase: {
    url: `${config.API_URL}/procurement/delete`,
    name: "删除采购单",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  receiptDoods: {
    url: `${config.API_URL}/procurement/receiptProduct`,
    name: "采购到货后收货",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 退货管理
  getReturnGoodsList: {
    url: `${config.API_URL}/cancelReturnable/list`,
    name: "获取退货列表",
    get: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addReturnGoods: {
    url: `${config.API_URL}/cancelReturnable/add`,
    name: "添加退货",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  cancelReturnGoods: {
    url: `${config.API_URL}/cancelReturnable/cancel`,
    name: "取消退货",
    post: async function (data = {}) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
}
